package com.blog.cloud.auth.sms.properties;

import com.xkcoding.justauth.autoconfigure.CacheProperties;
import com.xkcoding.justauth.autoconfigure.ExtendProperties;
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
import lombok.Getter;
import lombok.Setter;
import me.zhyd.oauth.config.AuthConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.NestedConfigurationProperty;
import org.springframework.stereotype.Component;

import java.net.Proxy;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

@Getter
@Setter
@Component
@ConfigurationProperties(prefix = DynamicSmsProperties.PREFIX)
public class DynamicSmsProperties {
    // 参考 DynamicDataSourceProperties
    public static final String PREFIX = "sms.dynamic";

    /**
     * 必须设置默认的源,默认master
     */
    private String primary = "master";

    /**
     * 是否启用严格模式,默认不启动. 严格模式下未匹配到短信源直接报错, 非严格模式下则使用默认短信源primary所设置的短信源
     */
    private Boolean strict = false;

    /**
     * 是否懒加载短信源
      */
    private Boolean lazy = false;

    /**
     * 每一个短信源
     */
    private Map<String, DynamicSmsProperty> source = new LinkedHashMap<>();




    private boolean enabled;
    private Map<String, AuthConfig> type = new HashMap<>();
    private JustAuthProperties.JustAuthHttpConfig httpConfig;

    @NestedConfigurationProperty
    private ExtendProperties extend;

    @NestedConfigurationProperty
    private CacheProperties cache = new CacheProperties();

    @Setter
    @Getter
    public static class JustAuthHttpConfig {
        private int timeout;
        private Map<String, JustAuthProperties.JustAuthProxyConfig> proxy;

        public JustAuthHttpConfig() {
        }

    }

    @Setter
    @Getter
    public static class JustAuthProxyConfig {
        private String type;
        private String hostname;
        private int port;

        public JustAuthProxyConfig() {
            this.type = Proxy.Type.HTTP.name();
        }

    }

}
